import { axios, api } from '@/Axios/index.js';
import _ from 'lodash';
// import { setNumSort } from './fun.js';

export default {
  namespaced: true,//customerList
  state: {
    FIRSTPAGE: 1,
    SIZE: 10,
    customerList: [{}, {}, {}],
    pages: {
      page: 1,
      size: 10,
    },
    activeCusArr: [],
    // expandPid: [],

    // activeApp: {},
  },
  mutations: {
    clear_updata: function (ctx, { list, state }) {
      console.log('%c [ list ]-22', 'font-size:13px; background:pink; color:#bf2c9f;', list)
      ctx.customerList.splice(0, ctx.customerList.length)
      list.forEach((v) => {
        ctx.customerList.push(Object.assign(
          { id: '', },
          {
            id: v.userid,
            face: v.avatar,
            eSCompanyId: v.eSCompanyId,
            isStar: v.isStar,
            lastMsg: v.lastMsg,
            lastTime: v.lastMsgTime,
            type: v.lastMsgType,
            tel: v.mobile,
            nickname: v.name,
            unread: v.noReadingCount,
            selfTag: v.selfTag,
          }
        ))
      })
      ctx.pages = Object.assign({}, state)
    },
  },
  getters: {
    置顶新客户消息: function (ctx) {

    },
    激活客户: function (ctx) {

    },
    更新部分消息未读数: function (ctx, { msg }) {

    },
  },
  actions: {
    init: function (ctx, { ceid: ceid }) {
      return api.get_App_Cus({
        companyEmployeeId: ceid,
        state: 1,
        page: ctx.state.FIRSTPAGE,
        size: ctx.state.SIZE,
      }).then((res) => {
        let arr = _.get(res.data, 'list', [])
        console.log('%c [ arr ]-65', 'font-size:13px; background:pink; color:#bf2c9f;', arr)
        ctx.commit('clear_updata', {
          list: arr,
          state: {
            current: ctx.state.FIRSTPAGE,
            size: ctx.state.SIZE,
            total: _.get(res.data, 'count', 0),
            maopao: _.get(res.data, 'maopaoCount', 0)
          }
        })
        return Promise.resolve('200')
      })
    },
    updata: function (ctx, payload) {
      let imCfg = Object.assign({},
        ctx.rootGetters['platform_app/getActivePlatform']('eSCompanyId'),
        ctx.rootGetters['platform_app/getActiveApp']('agentid'),
        ctx.rootGetters['postParams/get_im_cfg'](),
        ctx.rootGetters['postParams/getSelfTag'](),
      )
      console.log(imCfg)
      let crmCfg = Object.assign(
        {},
        ctx.rootGetters['postParams/get_crm_cfg'](),
      )
      console.log(crmCfg)
      return api.get_App_Cus({

      }).then((res) => {
        let arr = _.get(res.data, 'list', [])
        ctx.commit('clear_updata', {
          list: arr,
          state: {
            current: ctx.state.FIRSTPAGE,
            size: ctx.state.SIZE,
            total: _.get(res.data, 'count', 0),
            maopao: _.get(res.data, 'maopaoCount', 0)
          }
        })
        return Promise.resolve('200')
      })

      // ctx.rootGetters['loginInfo/getCEID'],
      // console.log(ctx)
      // console.log(ctx.rootGetters['loginInfo/getCEID'])
      // console.log(ctx.rootGetters['postParams/get_im_cfg'])
      // console.log(ctx.rootGetters['postParams/get_crm_cfg'])
      // console.log(payload)
    }
  },
}